package com.test30_IO流;

import java.io.File;
import java.util.Scanner;

/**
 * Scanner输入流
 */
public class Demo15_Scanner {

    public static void main(String[] args) throws Exception {
//        test1();
//        test2();
//        test3();
        test4();
    }

    /**
     * 读取键盘输入内容
     */
    public static void test1() {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入要发送的信息：");
        if (scanner.hasNext()) {
            String value = scanner.next();
            System.out.println("【数据回显】" + value);
        }
    }

    /**
     * 通过键盘读取数字
     */
    public static void test2() {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入您的年龄：");
        if (scanner.hasNextInt()) {
            int value = scanner.nextInt();
            System.out.println("【数据回显】" + value);
        } else {
            System.err.println("【ERROR】输入的内容不是数字。");
        }
    }

    /**
     * 实现正则处理
     */
    public static void test3() {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入注册邮箱：");
        if (scanner.hasNext("\\w+@\\w+\\.\\w+")) {
            String value = scanner.next("\\w+@\\w+\\.\\w+");
            System.out.println("【数据回显】" + value);
        } else {
            System.err.println("【ERROR】输入数据的格式不正确。");
        }
    }

    /**
     * 通过自定义分隔符
     */
    public static void test4() throws Exception {
        Scanner scanner = new Scanner(new File("F:" + File.separator + "muyan" + File.separator + "yootk.txt"));
        scanner.useDelimiter("\n");
        while (scanner.hasNext()) {
            String value = scanner.next();
            System.out.println(value);
        }
    }
}
